#include <iostream>
#include <string>
#include "user.pb.h"
#include "MprpcApplication.h"
#include "MprpcChannel.h"
#include "MprpcController.h"

int main(int argc, char **argv)
{
    MprpcApplication::Init(argc, argv);
    fixbug::UserServiceRpc_Stub stub(new MprpcChannel());
    fixbug::LoginRequest request;
    request.set_name("azq");
    request.set_pwd("123456");

    fixbug::LoginResponse response;
    MprpcController controller;

    stub.Login(&controller, &request, &response, nullptr);
    if (controller.Failed())
    {
        std::cout << controller.ErrorText() << std::endl;
    }
    else
    {
        if (0 == response.result().errcode())
        {
            std::cout << "rpc login repponse:" << response.success() << std::endl;
        }
        else
        {
            std::cout << "rpc login response error : " << response.result().errmsg() << std::endl;
        }

        fixbug::RegisterRequest req;
        req.set_id(1);
        req.set_name("jmm");
        req.set_pwd("123456");

        fixbug::RegisterResponse res;

        controller.Reset();
        stub.Register(&controller, &req, &res, nullptr);
        if (controller.Failed())
        {
            std::cout << controller.ErrorText() << std::endl;
        }
        if (0 == res.result().errcode())
        {
            std::cout << "rpc Register repponse:" << res.success() << std::endl;
        }
        else
        {
            std::cout << "rpc Register response error : " << res.result().errmsg() << std::endl;
        }
    }

    return 0;
}
